// JavaScript Document

function PageControl(name, totalRecord, currentPage, recordPerPage)
{
    this.name = name;
    this.nextPageStr = ">";
    this.prevPageStr = "<";
    this.firstPageStr = "<<";
    this.lastPageStr = ">>";
    this.linkStyleClass = "paging-link";
    this.pageStyleClass = "paging-number";
    this.pagePerSet = 10;

    this.currentPage = parseInt(currentPage);
    this.totalRecords = totalRecord;
    this.recordPerPage = recordPerPage;
	this.totalPages = Math.ceil(this.totalRecords / this.recordPerPage);
	this.setNo = Math.floor((this.currentPage - 1) / this.pagePerSet);

    this.printFirstPage = function ()
    {
        // === First === //
        if (this.currentPage > 1)
        {
            document.write("<a class='" + this.linkStyleClass + "' href=\"#1\" onclick=\"javascript:gotoPage(1)\">");
            document.write(this.firstPageStr);
            document.write("</a>");
        }
        else
        {
            document.write("&nbsp;");
        }
    };
    
    this.printPreviousPage = function ()
    {
        // === Previous === //
        if (this.currentPage > 1)
        {
            document.write("<a class='" + this.linkStyleClass + "' href=\"#1\" onclick=\"javascript:gotoPage (" + (this.currentPage - 1) + ")\">");
            document.write(this.prevPageStr);
            document.write("</a>");
        }
        else
        {
            document.write("&nbsp;");
        }
    };

	this.printNextPage = function ()
    {
        // === Next === //
        if (this.currentPage < this.totalPages)
        {
            document.write("<a class='" + this.linkStyleClass + "' href=\"#1\" onclick=\"javascript:gotoPage (" + (this.currentPage + 1) + ")\">");
            document.write(this.nextPageStr);
            document.write("</a>");
        }
        else
        {
            document.write("&nbsp;");
        }
    };
    
    this.printLastPage = function ()
    {
        // === Next === //
        if (this.currentPage < this.totalPages)
        {
            document.write("<a class='" + this.linkStyleClass + "' href=\"#1\" onclick=\"javascript:gotoPage (" + this.totalPages + ")\">");
            document.write(this.lastPageStr);
            document.write("</a>");
        }
        else
        {
            document.write("&nbsp;");
        }
    };
    
    this.printListPages = function ()
    {
        // === List of pages === //
        var startNo = ((this.setNo) * this.pagePerSet) + 1;
        var stopNo = ((this.setNo + 1) * this.pagePerSet );

        if (stopNo > this.totalPages)
        {
            stopNo = this.totalPages;
        }
        for (var i = startNo; i <= stopNo; i=i+1)
        {
            document.write("&nbsp;");
            if (i == this.currentPage)
            {
                document.write("<span class='" + this.pageStyleClass + "'>" + i + "</span>");
            }
            else
            {
                document.write("<a class='" + this.linkStyleClass + "' href=\"#1\" onclick=\"javascript:gotoPage (" + i + ")\">" + i + "</a>");
            }
        }
        document.write("&nbsp;");
    };
}

